<?php $_SESSION['create_id_album'] = '';?>
<div id="wall">
	<div id="ajax_wall"></div>
	<div id="page_wall" style="display:none">2</div>
    <div id="loading_wall_cm"></div>
    <div class="info" style="line-height:30px; text-align:center; font-weight:bold"><a id="view_more" href="javascript:;">Xem thêm</a></div>
</div><!--end wall-->

<script type="text/javascript" src="library/jquery.form.js"></script>
<script type="text/javascript" >
$(document).ready(function(){ 
	$('#photoimg').live('change',function(){
		$("#pic_box_load").html('');
		$("#pic_box_load").html('<img src="images/loader.gif" width="150" height="19" alt="Uploading...."/>');
		$("#imageform").ajaxForm({target: '.pic_box'}).submit();
	});
}); 
</script>

<script type="text/javascript">
$(document).ready(function(){
	function wall_cm(user,page){
		$.post("ajax_wall.php",{view_wall_all:"view_wall_all",user:user,page:page},function(data){
			$("#ajax_wall").html(data);
		});
	}
	wall_cm("<?php echo $user?>",1);
	$("#view_more").click(function(){
		var page = $("#page_wall").html();
		$("#view_more").css("display","none");
		$("#loading_wall_cm").html('<img src="images/loader.gif" style="margin:10px 0" />');
		$.post("ajax_wall.php",{view_wall_all:"view_wall_all",user:"<?php echo $user?>",page:page},function(data){
			if(data!=0){
				setTimeout(function(){
					$("#ajax_wall").append(data);
					$("#page_wall").html(parseInt(page)+1);
					$("#loading_wall_cm").html('');
					if(data!='')$("#view_more").css("display","block");
				},1000);
			}else $("#loading_wall_cm").html('');
		});
	});
	
	$("#hinhanh").live("click",function(){
		$("#frmUpload").css('display','block');
	});
	
	$("#textarea").live("click",function(){
		var content = $(this).val();
		if(content=="Bé thế nào rồi...") $(this).val("");
	});
	
	$("#btnstatus").live("click",function(){
		$(this).attr("readonly","readonly");
	});
	
	$("input[name=btnstatus]").live("click",function(){
		var content = CKEDITOR.instances['editor1'].getData();
		content = content.replace(/\s+/g,' ');
		content = content.replace(/Bé thế nào rồi.../g,'');
		content = content.replace(/B&eacute; thế n&agrave;o rồi.../g,'');
		content = content.replace(/&nbsp;/g,' ');
		content = content.replace(/<br \/> <br \/>/g,' ');
		content = content.replace(/   /g,' ');
		content = content.replace(/  /g,' ');
		content = $.trim(content);
		var share = $("select[name=share]").val();
		var photo = $("input[name=photo_name]").val();
		if(content!='' || photo!=''){
			CKEDITOR.instances['editor1'].setData('');
			$("textarea[name=data]").val('');
			var str = '<img src="images/loader.gif" style="margin:45px 20px" />';
			$("#loading_wall").html(str);
			$.post("ajax.php",{wall_content:"wall_content",content:content,share:share,photo:photo,user:"<?php echo $user?>"},function(data){
				if(data==1) setTimeout(function(){$("#loading_wall").html("");wall_cm("<?php echo $user?>",1);},500);
				else $("#loading_wall").prepend("<br />Không đăng được!");
			});
		}
	});
	
	$(".binhluan").live("click",function(){
		var id = ($(this).attr("class")).split(" ");
		$(".show_cm"+id[1]).css('display','inline');
		$("#comment"+id[1]).focus();
		$("#comment"+id[1]).keydown(function(e){
			var key = e.keyCode;
			if(key==13){
				var cm = $(this).val();
				if(cm!=''){
					$(this).attr("readonly",true);
					$.post("ajax.php",{comment:"comment",id:id[1],cm:cm},function(){
						var str = '<div class="comment"><div class="comment_img"><a href="index.html?user=<?php echo $idUser?>"><img src="<?php echo $avatar; ?>" alt=""></a></div><div class="comment_cm"><a href="index.html?user=<?php echo $idUser?>"><strong><?php echo $_SESSION['name']; ?></strong></a> ' + cm + '<div class="date"></div></div><div style="clear:both; height:1px"></div></div>';
						$("#ajax_wall_cm"+id[1]).prepend(str);
						$("#comment"+id[1]).val('');
						setTimeout(function(){$("#comment"+id[1]).attr("readonly",false);},500);
					});
				}
			}
		});
	});
	
	$(".info .delete").live("click",function(){
		var id = ($(this).attr("class")).split(" ");
		if(confirm("Bạn có muốn xóa?")){
			$.post("ajax.php",{deleteinfo:"deleteinfo",id:id[1],user:"<?php echo $user?>"},function(){
				$(".info"+id[1]).css('display','none');
			});
		}
	});
	
	$('.like').live("click",function(){
		var id = ($(this).attr('class')).split("_");
		var name = ($(this).attr('class')).split(" ");
		$.post("like.php",{user_like:"user_like",id:id[1],id2:<?php if(@$idUser) echo $idUser; else echo '""'?>},function(){
			if($('.'+name[1]).html()=='Thích') $('.'+name[1]).html('Bỏ thích');
			else $('.'+name[1]).html('Thích');
		});
	});
});
</script>